<template>
	<view class="orderDetail">
		<view v-if="pageData.status == 0" class="statusBox">
			<image src="../../static/image/order1.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="rightMessage">
				<view class="text">
					请尽快完成支付！
				</view>
				<view class="bottom">
					{{pageData.updated_at}}
				</view>
			</view>
		</view>
		<view v-if="pageData.status == 1" class="statusBox">
			<image src="../../static/image/order2.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="rightMessage">
				<view class="text">
					待发货
				</view>
				<view class="bottom">
					{{pageData.updated_at}}
				</view>
			</view>
		</view>
		<view v-if="pageData.status == 2" class="statusBox">
			<image src="../../static/image/order2.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="rightMessage">
				<view class="text">
					待收货
				</view>
				<view class="bottom">
					{{pageData.updated_at}}
				</view>
			</view>
		</view>
		<view v-if="pageData.status == 3" class="statusBox">
			<image src="../../static/image/order3.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="rightMessage">
				<view class="text">
					待评价
				</view>
				<view class="bottom">
					{{pageData.updated_at}}
				</view>
			</view>
		</view>
		<view v-if="pageData.status == 4" class="statusBox">
			<image src="../../static/image/order2.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="rightMessage">
				<view class="text">
					已完成
				</view>
				<view class="bottom">
					{{pageData.updated_at}}
				</view>
			</view>
		</view>
		<view v-if="pageData.status == -1" class="statusBox">
			<image src="../../static/image/order2.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="rightMessage">
				<view class="text">
					已取消
				</view>
				<view class="bottom">
					{{pageData.updated_at}}
				</view>
			</view>
		</view>

		<!-- 地址 -->
		<view class="addressBox">
			<view class="name_Phone">
				<text>{{pageData.area.name}}</text>
				<text>{{pageData.area.phone}}</text>
			</view>
			<view class="addressText">
				<text v-if="pageData.area.type =='1'">[默认]</text> {{pageData.area.area}}{{pageData.area.address}}
			</view>
		</view>

		<view class="productMessage">
			<view class="number">
				共计{{sumNumber}}件商品
			</view>

			<view class="detailBox" v-for="(productitem,productindex) in pageData.orders">
				<view class="detailBoxinner">
					<image :src="productitem.products_image" style="width: 160rpx;height: 160rpx;border-radius: 10rpx;"
						mode="aspectFill">
					</image>
					<view class="message">
						<view class="name">
							{{productitem.products_name}}
						</view>
						<view class="desc">
							规格：{{productitem.sku_text}}
						</view>
						<view class="bottom">
							<view class="price">
								₱{{productitem.price}}
							</view>
							<view class="number">
								x{{productitem.num}}
							</view>
						</view>
					</view>
				</view>


				<view v-if="productitem.status ==3" class="btnBoxpj" style="display: flex;justify-content: end;">
					<view class="btn" @click="handleEvaluate(productitem)">
						去评价
					</view>
				</view>

			</view>


		</view>
		<view class="orderbtnBox" style="padding-bottom: 20rpx;">
			<!-- 	<view v-if="pageData.status > 0" class="orderbtn" style="margin-left: 560rpx;" @click="handleApplyfor">
				申请售后
			</view> -->
			<!-- <view class="orderbtn">
					去评价
				</view> -->
		</view>

		<view class="ordermessage" style="margin-top: 3rpx;">

			<view class="messageItem">
				<view class="lable">
					订单编号：
				</view>
				<view class="value">
					<text class="copy">复制</text>
					<text class="">
						{{pageData.order_no}}
					</text>
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					下单时间：
				</view>
				<view class="value">
					<view class="">
						{{pageData.created_at}}
					</view>
				</view>
			</view>
			<!-- 	<view class="messageItem">
				<view class="lable">
					支付状态：
				</view>
				<view class="value">
					<view v-if="pageData.status == 0" class="">
						未支付
					</view>
					<view v-else class="">
						已支付
					</view>
				</view>
			</view> -->
			<!-- 	<view class="messageItem">
				<view class="lable">
					支付时间：
				</view>
				<view class="value">
					<view class="">
						{{pageData.pay_time}}
					</view>
				</view>
			</view> -->
			<!-- 	<view class="messageItem">
				<view class="lable">
					支付方式：
				</view>
				<view class="value">
					<view class="">
						余额
					</view>
				</view>
			</view> -->
			<view class="messageItem">
				<view class="lable">
					商品总额：
				</view>
				<view class="value">
					<view class="">
						₱{{pageData.price}}
					</view>
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					邮费：
				</view>
				<view class="value">
					<view class="">
						₱{{pageData.freight}}
					</view>
				</view>
			</view>
			<view class="messageItem">
				<view class="lable">
					总计：
				</view>
				<view class="value">
					<view class="">
						₱{{Number(pageData.price) + Number(pageData.freight) }}
					</view>
				</view>
			</view>
			<!-- <view class="messageItem">
				<view class="lable">
					积分抵扣：
				</view>
				<view class="value">
					<view class="">
						-₱10
					</view>
				</view>
			</view> -->
		</view>

		<view v-if="pageData.delivery_time" class="actualPay">
			<view class="lable">
				配送时间：
			</view>
			<view class="value">
				{{pageData.delivery_time}}
			</view>
		</view>
		<!-- <view class="actualPay">
			<view class="lable">
				实付款：
			</view>
			<view class="value">
				₱{{pageData.price*pageData.num + (pageData.freight)*1}}
			</view>
		</view> -->

		<view class="" style="height: 150rpx;"></view>

		<view class="btnBox">
			<!-- <view v-if="pageData.status == 0"
				style="background-color: #ffffff;color: #439B05;border: 1rpx solid #439B05;margin-left: 100rpx;"
				class="btn" @click="celshow = true">
				取消订单
			</view> -->
			<!-- <view v-if="pageData.status == 0" style="margin-left: 20rpx;" class="btn" @click="payshow = true">
				立即支付
			</view> -->
			<!-- <view v-if="pageData.status == 1" style="margin-left: 370rpx;" class="btn" @click="handleApplyfor">
				申请售后
			</view> -->
			<view v-if="pageData.status == 2" style="margin-left: 370rpx;" class="btn" @click="delshow = true">
				确认收货
			</view>
			<!-- 	<view v-if="pageData.status == 3" style="margin-left: 370rpx;" class="btn" @click="handleAgingou">
				再次购买
			</view> -->
		</view>


		<u-modal :show="delshow" :title="title" :showCancelButton="true" @confirm="handlefinishorder"
			@cancel="delshow = false" confirmColor="#439B05"></u-modal>

		<u-modal :show="celshow" :title="celtitle" :showCancelButton="true" @confirm="handlecancellation"
			@cancel="celshow = false" confirmColor="#439B05"></u-modal>

		<u-modal :show="payshow" :title="paytitle" :showCancelButton="true" @confirm="handlePay"
			@cancel="payshow = false" confirmColor="#439B05"></u-modal>


	</view>
</template>

<script>
	import {
		ordersdetail,
		finishorder,
		cancellation,
		waitpay
	} from "@/api/api.js"
	export default {
		data() {
			return {
				pageId: "",
				pageData: {},
				title: "确定要收货吗？",
				delshow: false,
				celshow: false,
				celtitle: "确定要取消该订单吗？",
				payshow: false,
				paytitle: "您确定要支付该订单吗",
				sumNumber: 0,
			}
		},
		onLoad(options) {
			console.log("333", options)
			this.pageId = options.id
			this.handleGetdetail()
		},
		methods: {
			async handleGetdetail() {
				let res = await ordersdetail({
					id: this.pageId
				})
				this.pageData = res.data
				res.data.orders.forEach((item, index) => {
					this.sumNumber = this.sumNumber + item.num
				})
				console.log("33", this.pageData.status)
			},
			async handlefinishorder() {
				let res = await finishorder({
					id: this.pageId
				})
				if (res.code == 1000) {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
					this.delshow = false
					this.handleGetdetail()
				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
				}
			},
			//取消订单
			async handlecancellation() {
				let res = await cancellation({
					id: this.pageData.id
				})
				if (res.code == 1000) {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
					this.handleGetdetail()
					this.celshow = false
				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
				}
			},

			//立即支付
			async handlePay() {
				let subres = await waitpay({
					pay_type: '2',
					order_no: this.pageData.order_no
				})
				//确认支付
				if (subres.code == 1000) {
					uni.showToast({
						title: subres.message,
						icon: "none",
						duration: 2000
					});
					this.payshow = false
					setTimeout(() => {
						this.handleGetdetail()
					}, 2000)

				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
				}
			},
			handleAgingou() {
				// console.log("pageData",this.pageData)
				uni.navigateTo({
					url: `/pages/home/detail?id=${this.pageData.products_id}`
				})
			},
			handleApplyfor() {
				uni.navigateTo({
					url: `./applyFor?data=${JSON.stringify(this.pageData)}`
				})
			},
			handleEvaluate(item) {
				uni.navigateTo({
					url: `./evaluate?data=${JSON.stringify(item)}`
				})
				event.stopPropagation()
			},

		}
	}
</script>

<style scoped lang="scss">
	.btnBoxpj {
		margin-top: 20rpx;

		.btn {
			width: 160rpx;
			height: 64rpx;
			background: #439B05;
			border-radius: 100rpx;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 64rpx;
			text-align: center;
		}

		.btns {
			border: 2rpx solid #CCCCCC;
			background: #FFFFFF;
			color: #333333;
		}
	}

	.orderbtnBox {
		display: flex;
		background-color: #ffffff;

		.orderbtn {
			width: 160rpx;
			height: 64rpx;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			opacity: 1;
			border: 2rpx solid #CCCCCC;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 64rpx;
			text-align: center;
			border-radius: 100rpx;
		}
	}

	.btnBox {
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #ffffff;
		position: fixed;
		bottom: 0;
		display: flex;

		.btn {
			width: 300rpx;
			height: 88rpx;
			background: #439B05;
			border-radius: 200rpx 200rpx 200rpx 200rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 88rpx;
			text-align: center;
			// margin-left: 370rpx;
		}
	}

	.orderDetail {
		.statusBox {
			width: 100%;
			height: 160rpx;
			background: #439B05;
			padding: 40rpx 30rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;

			.rightMessage {
				margin-left: 20rpx;

				.text {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 33rpx;
				}

				.bottom {
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 28rpx;
					margin-top: 6rpx;
				}
			}
		}

		.addressBox {
			width: 100%;
			height: 138rpx;
			background: #FFFFFF;
			padding: 30rpx;
			box-sizing: border-box;

			.name_Phone {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 33rpx;
			}

			.addressText {
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 28rpx;
				// margin-top: 10rpx;
			}
		}

		.productMessage {
			width: 100%;
			// height: 300rpx;
			background-color: #ffffff;
			padding: 30rpx;
			box-sizing: border-box;
			margin-top: 1rpx;

			.number {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 60rpx;
				border-bottom: 1rpx solid #F5F5F5;
			}

			.detailBox {
				margin-top: 24rpx;

				.detailBoxinner {
					display: flex;
					align-items: center;
				}

				.message {
					margin-left: 20rpx;

					.name {
						width: 450rpx;
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #333333;
						line-height: 38rpx;
						white-space: nowrap;
						/* 设置不换行 */
						overflow: hidden;
						/* 设置超出部分隐藏 */
						text-overflow: ellipsis;
					}

					.desc {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 28rpx;
						margin-top: 20rpx;
					}

					.bottom {
						display: flex;
						width: 100%;
						justify-content: space-between;
						margin-top: 34rpx;

						.price {
							font-size: 32rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #333333;
							line-height: 38rpx;
						}

						.number {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #999999;
							line-height: 33rpx;
						}
					}
				}
			}
		}


		.ordermessage {
			width: 100%;
			background: #FFFFFF;
			padding: 30rpx;
			box-sizing: border-box;

			.messageItem {
				display: flex;
				justify-content: space-between;
				margin-bottom: 20rpx;


				.lable {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 33rpx;
				}

				.value {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #999999;
					line-height: 33rpx;
				}

				.copy {
					width: 60rpx;
					height: 30rpx;
					border-radius: 30rpx;
					border: 2rpx solid #CCCCCC;
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #999999;
					line-height: 28rpx;
					display: inline-block;
					text-align: center;
					margin-right: 10rpx;
				}
			}
		}


		.actualPay {
			width: 100%;
			height: 100rpx;
			background: #FFFFFF;
			padding: 30rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			margin-top: 1rpx;

			.lable {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 33rpx;
			}

			.value {
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #FF3D3D;
				line-height: 38rpx;
			}
		}
	}
</style>